package com.lin.missyou.dto;

import com.fasterxml.jackson.core.type.TypeReference;
import com.lin.missyou.util.GenericAndJson;
import lombok.Getter;
import lombok.Setter;

import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import java.math.BigDecimal;
import java.util.List;

/**
 * 前端传递过来的参数
 * @author gcq
 * @Create 2021-11-08
 */
@Setter
@Getter
public class OrderDTO {

    /**
     * 总价格
     */
    @DecimalMin(value = "0.00", message = "不在合法范围内")
    @DecimalMax(value = "9999999.99", message = "不再合法范围内")
    private BigDecimal totalPrice;
    /**
     * 总价格
     */
    private BigDecimal finalTotalPrice;
    /**
     * 优惠券Id
     */
    private Long couponId;
    /**
     * SkuInfo
     */
    private List<SkuInfoDTO> skuInfoList;
    /**
     * 地址
     */
    private String address;

    public OrderAddressDTO getAddress() {
        if (this.address == null) {
            return null;
        }
        return GenericAndJson.jsonToList(this.address, new TypeReference<OrderAddressDTO>() {
        });
    }

    public void setAddress(OrderAddressDTO address) {
        if (address == null) {
            return;
        }
        this.address = GenericAndJson.objectToJson(address);
    }
}